//
//  BKMyOrderApplyReturnGoodsFooterCell.m
//  bestkeep
//
//  Created by Mr. Wu on 16/12/20.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKMyOrderApplyReturnGoodsFooterCell.h"
#import "BK_OD_Tool.h"
@implementation BKMyOrderApplyReturnGoodsFooterCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _questionLabel = [UILabel new];
        _questionLabel.text = @"问题描述";
        _questionLabel.textColor = RGB(102, 102, 102);
        _questionLabel.font = [UIFont systemFontOfSize:14.0];
        [self.contentView addSubview:_questionLabel];
        
        [_questionLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.contentView.mas_top).offset(5);
            make.left.mas_equalTo(self.contentView.mas_left).offset(ApplicationBackGauge);
        }];
        
        _applyTextView = [UITextView new];
        [_applyTextView setBackgroundColor:[UIColor whiteColor]];
        _applyTextView.layer.borderColor = [UIColor grayColor].CGColor;
        _applyTextView.layer.borderWidth = 0.5;
        _applyTextView.font = [UIFont systemFontOfSize:12.0];//15->12
        _applyTextView.textColor = RGB(204, 204, 204);// grayColor->204;
        _applyTextView.text = @"请在此描述详细问题";
        _applyTextView.delegate = self;
        [self.contentView addSubview:_applyTextView];
        
        [_applyTextView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_questionLabel.mas_bottom).offset(10);
            make.right.mas_equalTo(self.contentView.mas_right).offset(-ApplicationBackGauge);
            make.left.mas_equalTo(self.contentView.mas_left).offset(ApplicationBackGauge);
            make.height.mas_equalTo(@(72));//70->72
        }];
        
        _applyLabel = [UILabel new];
        _applyLabel.text = @"上传图片";
        _applyLabel.textColor = RGB(102, 102, 102);
        _applyLabel.font = [UIFont systemFontOfSize:14.0];//15->14
        _applyLabel.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_applyLabel];
        
        [_applyLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_applyTextView.mas_bottom).offset(10);
            make.left.mas_equalTo(self.contentView.mas_left).offset(ApplicationBackGauge);
        }];
        
        _applyAddImage = [UIButton new];
        _applyAddImage.layer.borderColor = [UIColor grayColor].CGColor;
        _applyAddImage.layer.borderWidth = 0.5;
        _applyAddImage.backgroundColor = [UIColor whiteColor];
        [_applyAddImage setTitle:@"+" forState:UIControlStateNormal];
        [_applyAddImage.titleLabel setFont:[UIFont systemFontOfSize:25.0]];
        [_applyAddImage setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.contentView addSubview:_applyAddImage];
        
        [_applyAddImage mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_applyLabel.mas_bottom).offset(10);
            make.left.mas_equalTo(self.contentView.mas_left).offset(ApplicationBackGauge);
            make.width.mas_equalTo(@(72));
            make.height.mas_equalTo(@(72));
        }];
        
        _applyAddImage1 = [UIButton new];
        _applyAddImage1.hidden = YES;
        _applyAddImage1.layer.borderColor = [UIColor grayColor].CGColor;
        _applyAddImage1.layer.borderWidth = 0.5;
        _applyAddImage1.backgroundColor = [UIColor whiteColor];
        [_applyAddImage1 setTitle:@"+" forState:UIControlStateNormal];
        [_applyAddImage1.titleLabel setFont:[UIFont systemFontOfSize:25.0]];
        [_applyAddImage1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.contentView addSubview:_applyAddImage1];
        
        [_applyAddImage1 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_applyLabel.mas_bottom).offset(10);
            make.left.mas_equalTo(self.contentView.mas_left).offset(92);
            make.width.mas_equalTo(@(72));
            make.height.mas_equalTo(@(72));
        }];
        
        _applyAddImage2 = [UIButton new];
        _applyAddImage2.hidden = YES;
        _applyAddImage2.layer.borderColor = [UIColor grayColor].CGColor;
        _applyAddImage2.layer.borderWidth = 0.5;
        _applyAddImage2.backgroundColor = [UIColor whiteColor];
        [_applyAddImage2 setTitle:@"+" forState:UIControlStateNormal];
        [_applyAddImage2.titleLabel setFont:[UIFont systemFontOfSize:25.0]];
        [_applyAddImage2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.contentView addSubview:_applyAddImage2];
        
        [_applyAddImage2 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_applyLabel.mas_bottom).offset(10);
            make.left.mas_equalTo(self.contentView.mas_left).offset(174);
            make.width.mas_equalTo(@(72));
            make.height.mas_equalTo(@(72));
        }];
        
        
        _applyExplainLabel = [UILabel new];
        _applyExplainLabel.text = @"最多上传3张,每张不超过5M,支持PNG、JPG";
        _applyExplainLabel.textColor = RGB(153, 153, 153);//grayColor -> RGB(153, 153, 153)
        _applyExplainLabel.font = [UIFont systemFontOfSize:11.0];//8->11
        [self.contentView addSubview:_applyExplainLabel];
        
        [_applyExplainLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_applyAddImage.mas_bottom).offset(10);
            make.left.mas_equalTo(self.contentView.mas_left).offset(ApplicationBackGauge);
        }];
    }
    return self;
}
- (void)textViewDidBeginEditing:(UITextView *)textView {
    
    if ([textView.text isEqualToString:@"请在此描述详细问题"]) {
        
        textView.text = @"";
        
    }
    
}
//通过判断表层TextView的内容来实现底层TextView的显示于隐藏
- (void)textViewDidEndEditing:(UITextView *)textView {
    
    if (textView.text.length < 1) {
        
        textView.text = @"请在此描述详细问题";
        
    }
    [self.delegate getTextFieldString:textView.text];
}
- (BOOL)textView:(UITextView *)textView
shouldChangeTextInRange:(NSRange)range
 replacementText:(NSString *)text
{
    //判断加上输入的字符，是否超过界限
    
    if (textView.text.length > 100)
    {
        textView.text = [textView.text substringToIndex:100];
        return NO;
    }
    //    点击return回收键盘
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}


@end
